//
//  YZCConsultCell.m
//  LOLerBox
//
//  Created by 杨智超 on 16/1/16.
//  Copyright © 2016年 蓝鸥科技. All rights reserved.
//

#import "YZCConsultCell.h"

@implementation YZCConsultCell

- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.titleLabel = [[UILabel alloc]init];
        self.titleLabel.numberOfLines = 0;
        self.titleLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:self.titleLabel];
        [_titleLabel release];
        
        self.descLabel = [[UILabel alloc]init];
        self.descLabel.numberOfLines = 0;
        self.descLabel.textColor = [UIColor grayColor];
        self.descLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.descLabel];
        [_descLabel release];
        
        self.publishedLabel = [[UILabel alloc]init];
        /* 字体右对齐 */
        self.publishedLabel.textAlignment = UITextAlignmentRight;
        self.publishedLabel.font = [UIFont systemFontOfSize:10];
        self.publishedLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:self.publishedLabel];
        [_publishedLabel release];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat h = [[self class]heightWithText:_titleLabel.text];
    _titleLabel.frame = CGRectMake(5, 20, 350, h);
    CGFloat h1 = [[self class]heightWithText:_descLabel.text];
    _descLabel.frame = CGRectMake(5, 20 + h + 10, 375 - 10, h1);
    _publishedLabel.frame = CGRectMake(300, 20 + h + 10 + h1 + 5, 70, 10);
}

- (void)setModel:(YZCConsultModel *)model {
    if (model != _model) {
        _model = model;
    }
    _model.title = _titleLabel.text;
    _model.desc = _descLabel.text;
    NSString *published = _model.published.description;
    published = _publishedLabel.text;
}

+ (CGFloat)heightWithText:(NSString *)text {
    
    NSDictionary *dic = @{NSFontAttributeName: [UIFont systemFontOfSize:12]};
    CGSize s = CGSizeMake(365, 1000);
    CGRect r = [text boundingRectWithSize:s options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return r.size.height;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
